﻿using BoriPeter.FatSecret.Models;
using BoriPeter.FitnessJournal8.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoriPeter.FatSecret.Converters
{
    public static class FoodGetConverter
    {
        public static Food Convert(this FoodGetModel _foodGetModel)
        {
            Food food = new Food();
            food.Name = _foodGetModel.FoodName;
            food.Id = _foodGetModel.FoodId;
            food.Type = _foodGetModel.FoodType;
            food.Id = _foodGetModel.FoodId;
            if (_foodGetModel.Servings != null)
            {
                food.Servings = new System.Collections.ObjectModel.ObservableCollection<Serving>();
                foreach (var item in _foodGetModel.Servings)
                {
                    Serving serving = new Serving();
                    serving.CalciumRDI = item.Calcium;
                    serving.CaloriesKcal = item.Calories;
                    serving.CarbohydrateGram = item.Carbohydrate;
                    serving.CholesterolMg = item.Cholesterol;
                    serving.Description = item.ServingDescription;
                    serving.FatGram = item.Fat;
                    serving.FiberGram = item.Fiber;
                    serving.Id = item.ServingId;
                    serving.IronRDI = item.Iron;
                    serving.MeasurementDescription = item.MeasurementDescription;
                    serving.MetricNumberOfUnits = item.NumberOfUnits;
                    serving.MetricUnit = item.MetricServingUnit;
                    serving.MonosaturatedFatGram = item.MonounsaturatedFat;
                    serving.NumberOfUnits = item.NumberOfUnits;
                    serving.PolyunsaturatedFatGram = item.PolyunsaturatedFat;
                    serving.PotassiumMg = item.Potassium;
                    serving.ProteinGram = item.Protein;
                    serving.SaturatedFatGram = item.SaturatedFat;
                    serving.SodiumMg = item.Sodium;
                    serving.SugarGram = item.Sugar;
                    serving.TransFatGram = item.TransFat;
                    serving.UnitOfMeasure = item.MeasurementDescription;
                    serving.VitaminARDI = item.VitaminA;
                    serving.VitaminCRDI = item.VitaminC;

                    food.Servings.Add(serving);
                }
                food.SelectedServing = food.Servings[0];
            }

            return food;
        }
    }
}
